<?
switch($act){
	case "del":
	Del();
	break;
	
	case "dellist":
	DelList();
	break;
		
	case "order":
	Order();
	break;
	
	case "finish":
	Finish();
	$tpl="finish";
	$title_page = "CMS - Finished Orders";
	break;
	
	case "change_status":
	change_status();
	//$tpl="list";
	break;
	
	case "change_complete":
	change_complete();
	//$tpl="list";
	break;
	
	default:
	ShowList();
	$title_page = "CMS - Orders";
	$tpl="list";
}

function Finish()
{
	global $db,$orders,$page,$plpage,$set_per_page,$c;
	$set_per_page=20; 
	$sql="select * from orders where complete = 1";		
		
	$c = $db->numRows($db->query($sql));
	$plpage = plpage($sql,$page,$set_per_page);
	$sqlstmt = sqlmod($sql,$page,$set_per_page);	
	$orders = $db->getAll($sqlstmt);
}

function ShowList()
{
	global $db,$orders,$page,$plpage,$set_per_page,$c;
	$set_per_page=20; 
	
	$sql="select * from orders where complete <> '1'";		

	$c = $db->numRows($db->query($sql));
	$plpage = plpage($sql,$page,$set_per_page);
	$sqlstmt = sqlmod($sql,$page,$set_per_page);	
	$orders = $db->getAll($sqlstmt);
}
function change_status()
{
	global $db;
	$id=$_GET["id"];

	$status = $_GET['current']==1?0:1;
	$sql="update orders set status=".$status." where id=".$id;
	$db->query($sql);	
		
	$msg="Update successfully";	
	
	$page="admin.php?do=orders". (isset($_GET['cid'])?'&cid='.$_GET['cid']:'') . (isset($_GET['page'])?'&page='.$_GET['page']:'');
	
	$_SESSION['mess'] = $msg;
	page_transfer2($page);
}
function change_complete()
{
	global $db;
	$id=$_GET["id"];

	$complete = $_GET['current']==1?0:1;
	$sql="update orders set complete=".$complete." where id=".$id;
	$db->query($sql);	
	
	echo $sql;
		
	$msg="Update successfully";	
	
	$page="admin.php?do=orders&act=finish". (isset($_GET['cid'])?'&cid='.$_GET['cid']:'') . (isset($_GET['page'])?'&page='.$_GET['page']:'');
	
	$_SESSION['mess'] = $msg;
	page_transfer2($page);
}
function DelList()
{
	global $db;
	$id=$_POST["iddel"];		
	for($i=0;$i<count($id);$i++){
		
		$sql="delete from orders where id=".$id[$i];

		$db->query($sql);		
	}
	$msg="Delete successfully";		
	$_SESSION['mess'] = $msg;
	$page="admin.php?do=orders". (isset($_GET['page'])&&$_GET['page']=='finish'?'&act=finish':''). (isset($_GET['page'])?'&page='.$_GET['page']:'');
	page_transfer2($page);
}
function Del()
{
	global $db;
	$id=$_GET["id"];

	$sqlstmt="select img from `orders` where id=$id";
	$r = $db->getRow($sqlstmt);
	if(file_exists($r['img'])) unlink($r['img']);		
	$sql="delete from categories where pid=337 and alias=".$id;
	$db->query($sql);	
	$sql="delete from orders  where id=".$id;
	$db->query($sql);	
		
	$msg="Delete successfully";		
	$_SESSION['mess'] = $msg;
	$page="admin.php?do=orders". (isset($_GET['cid'])?'&cid='.$_GET['cid']:'') . (isset($_GET['page'])?'&page='.$_GET['page']:'');
	page_transfer2($page);
}

?>